<template>
	<view>
		<view class="cu-list grid col-3 no-border">

			<view class="cu-item text-center"> 
				<view>
					<view class="uni-h3 row">{{type}}</view>
				</view> 
			</view>
			<view class="cu-item text-center"> 
				<view> 
					<view class="uni-h3 row" @tap="cc">→</view> 
				</view>
				 


			</view>
			<view class="cu-item text-center">

				<view>
					<view class="uni-h3  row">{{type2}}</view>
				</view>

			</view>

		</view>
		<view class="cu-list grid col-2 no-border">
			<view class="cu-item text-left">

				<view>
					<view class="text-lg row margin-left">{{wall[type]}}</view>
					<view class="text-df row text-gray margin-left-sm">BJ</view>
					<view class="text-df row text-gray margin-left-sm">可用</view>
				</view>
				<!-- <view style="margin-right: 26px;">
					<view class="text-lg row">{{type1_freeze}}</view>
					<view class="text-df row text-gray margin-left-sm">{{type}}</view>
					<view class="text-df row text-gray margin-left-sm">冻结</view>
				</view>
				<view style="margin-right: 26px;">
					<view class="text-lg row">{{type1_total}}</view>
					<view class="text-df row text-gray margin-left-sm">{{type}}</view>
					<view class="text-df row text-gray margin-left-sm">全部</view>
				</view> -->
			</view>
			<!-- <view class="cu-item text-center"></view> -->
			<view class="cu-item text-right">

				<view>
					<view class="text-lg row ">{{wall[type2]}}</view>
					<view class="text-df row text-gray margin-left-sm">BJ</view>
					<view class="text-df row text-gray margin-left-sm margin-right">可用</view>
				</view>
				<!-- <view style="margin-left: 9px;">
					<view class="text-lg row">{{type2_freeze}}</view>
					<view class="text-df row text-gray margin-left-sm">{{type2}}</view>
					<view class="text-df row text-gray margin-left-sm">冻结</view>
				</view>
				<view style="margin-left: 9px;">
					<view class="text-lg row">{{type2_total}}</view>
					<view class="text-df row text-gray margin-left-sm">{{type2}}</view>
					<view class="text-df row text-gray margin-left-sm">全部</view>
				</view> -->
			</view>
		</view>


		<form @submit="" @reset="">
			<!-- <view class="cu-form-group">
				<view class="title">币种选择</view>
				<picker @change="PickerChange" :value="type" :range="picker">
					<view class="picker">
						{{type}}
					</view>
				</picker>
			</view>
			<view class="cu-form-group">
				<view class="title">币种选择</view>
				<picker @change="PickerChange2" :value="type2" :range="picker">
					<view class="picker">
						{{type2}}
					</view>
				</picker>
			</view> -->

			<view class="cu-form-group ">
				<view class="title">划转数量</view>
				<input placeholder="请输入划转数量" name="input" v-model="nums"></input>

			</view>
			<!-- <view class="cu-form-group">
				<view class="solid-bottom text-xs  ">
					<text class="text-gray">可用数量：900 {{type}}</text>
				</view>
			</view> -->




		</form>
		<view class="cu-list grid col-1 no-border tij">
			<view class="padding flex flex-direction">
				<button class="cu-btn bg-yellow lg" @tap="sub">提交</button>
			</view>

			<!-- <view class="flex-sub  ">
				<view class="solid-bottom text-xs padding">
					温馨提示：提币前请再次确认您的地址
				</view>
			</view> -->
		</view>
<key-words :show_key="show_key" :show_subTitle="false" :price="'1.00'" @closeFuc="closeFuc" @getPassword="getPassword"></key-words>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex';
	export default {
		data() {
			return {
				type: '百金点灯',
				type2: 'SSEX',
				// picker: ['百金点灯', 'SSEX'],

				addr: {
					BTC: '0X122456432465661',
					ETH: '0X142452323222261',
					EMP: '0X132456433265661',
				},
				nums: '',
				binfo: {},
				tradetimer: [],
				rate: {
					EMP2BJ: 0,
					BJ2EMP: 0,
				},
				wall: {},
				post:false,
				inc: false,
				show_key: false,
				check:false,

			}
		},
		computed: {
			...mapState({
				userinfo: state => state.user.userinfo,
				myconfig: state => state.user.myconfig
			}),
			hasLogin() {
				return this.userinfo.id ? true : false
			},
			picker() {
				return [this.type, this.type2];
			},
			// type1_use() {
			// 	return this.userinfo[this.myconfig.transfers['BJ']];
			// },
			// type2_use() {
			// 	return this.userinfo[this.myconfig.transfers['BJ']];
			// },
			// type1_freeze() {
			// 	return 0;
			// },
			// type2_freeze() {
			// 	return 0;
			// },
			// type1_total() {
			// 	return 1;
			// },
			// type2_total() {
			// 	return 1;
			// }

		},

		onShow() {
			this.init();
		},
		onBackPress() {
			this.cleartimer();
		},
		methods: {
			...mapActions(['getUserinfo', 'myConfig']),
			init() {
				this.getUserinfo();
				this.myConfig();
				this.type = this.myconfig.app2app['a'];
				this.type2 = this.myconfig.app2app['b'];
				this.$set(this.wall, this.type, 0);
				this.$set(this.wall, this.type2, 0);
				this.wall[this.type2] = this.userinfo[this.myconfig.cointype2['BJ']];
				this.getother();

			},
			cleartimer() {
				console.log(this.tradetimer.length)
				if (this.tradetimer.length > 0) {
					for (let i = 0; i < this.tradetimer.length; i++) {
						clearInterval(this.tradetimer[i])
					}
					this.tradetimer = []
				}
			},
			getcoinlist() {
				//行情列表
				this.$http.post('btc.binfo').then(res => {
					this.binfo = res.data;
				})
			},
			PickerChange(e) {
				this.type = this.picker[e.detail.value];
			},
			PickerChange2(e) {
				this.type2 = this.picker[e.detail.value];
			},
			//加法
			accAdd(arg1, arg2) {
				var r1, r2, m, n;
				try {
					r1 = arg1.toString().split(".")[1].length
				} catch (e) {
					r1 = 0
				}
				try {
					r2 = arg2.toString().split(".")[1].length
				} catch (e) {
					r2 = 0
				}
				m = Math.pow(10, Math.max(r1, r2));
				//last modify by deeka
				//动态控制精度长度
				n = (r1 >= r2) ? r1 : r2;
				var ree = ((arg1 * m + arg2 * m) / m).toFixed(n);
				return ree > 0 ? ree : 0;
			},
			cc() {
				let eee = this.type;
				this.type = this.type2;
				this.type2 = eee;
			},
			sub() {
				if(this.post){
					return false;
				} 
				
				if (this.nums <= 0) {
					this.$api.msg('数量不能为0')
					return false;
				}

				if (parseInt(this.wall[this.type]) < parseInt(this.nums)) {
					this.$api.msg('超过最大可用数量')
					return false;
				}
				
				if(!this.check){
					this.show_key = true;
					return 1; 
				}  

				let send = {
					type1: this.type,
					type2: this.type2,
					nums: this.nums,
				}

				//提交
				this.post=true;
				this.$http.post('Transfer.app2coin', send).then(re => {
					 
					if (re.msg) {
						this.$api.msg(re.msg)
						this.getUserinfo().then(re=>{
							 
							 this.wall[this.myconfig.app2app['b']] =re.data[this.myconfig.cointype2['BJ']];
						}) 
					    this.getother();
						
						
					}
					this.post=false;
				})
			},
			getother() {
				this.$http.post('Transfer.getUserBj').then(re => {
					 
					if (re.data.status == 1) {
						this.wall[this.myconfig.app2app['a']] = re.data.data.BjNum;  
					} else {
						this.$api.msg(re.data.message)
					}
				})
			},
			closeFuc() {
				this.show_key = false;
			},
			//密码输入完需要执行的方法
			getPassword(msg) {
				//msg:密码   例如:{msg:123456}
				console.log(msg)
				let data={
					password2:msg.password
				}
				this.$http.post('user.checkpass', data).then(res => {
					console.log(res)
					if(res.code==1){
						this.check=true;
						this.sub();
					}else{
						this.$api.msg(res.msg); 
					}  
				})
				this.closeFuc();
			},
		}
	}
</script>

<style>
	.row {
		display: inline;
	}

	.tij {
		bottom: 0px;
		position: absolute;
		width: -webkit-fill-available;
	}
</style>
